<?php
/*
param $image   图象资源
param size     字体大小
param angle    字体输出角度
param showX    输出位置x坐标
param showY    输出位置y坐标
param font    字体文件位置
param content 要在图片里显示的内容
*/
class ChinaText {

	var $font = './Public/fonts/simsun.ttc'; //如果没有要自己加载到相应的目录下（本地www）
	var $size = 18;

	var $multexts = null;
	var $bg='';
	
	function ChinaText($title_text=null,$bg='11.jpg') {
		$this->multexts = $title_text;
		$this->bg = $bg;
	
		$this->show ();
	}
	function createText($instring) {
		$outstring = "";
		$max = strlen ( $instring );
		for($i = 0; $i < $max; $i ++) {
			$h = ord ( $instring [$i] );
			if ($h >= 160 && $i < $max - 1) {
				$outstring .= substr ( $instring, $i, 2 );
				$i ++;
			} else {
				$outstring .= $instring [$i];
			}
		}
		return $outstring;
	}
	
	function show() {
		//输出头内容
		Header ( "Content-type: image/png" );
		//建立图象
		//$image = imagecreate(400,300);
		$image = imagecreatefromjpeg ( "./Public/".$this->bg); //这里的图片，换成你的图片路径
		//定义颜色
		$red = ImageColorAllocate ( $image, 255, 0, 0 );
		$white = ImageColorAllocate ( $image, 255, 255, 255 );
		$black = ImageColorAllocate ( $image, 0, 0, 0 );
		//填充颜色
		//ImageFilledRectangle($image,0,0,200,200,$red);
		//显示文字
		foreach ($this->multexts as $tx){
			imagettftext (
			$image,
			$this->size,
			$tx['angle'],
			$tx['showX'],
			$tx['showY'],
			$black,
			$this->font,
			$tx['text'] );
				
		}
		//显示图形
		imagejpeg ( $image );
	}
}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	